//
//  MySenderAppointmentViewController.m
//  StraightTrain
//
//  Created by mk on 15/12/2.
//  Copyright © 2015年 mk. All rights reserved.
//

#import "MySenderBookingViewController.h"
#import "BookingData.h"
#import "MySenderBookingCell.h"
#import "BookingDetailsViewController.h"

@interface MySenderBookingViewController ()
{
   BookingListData * bookingList;//等待预约列表

}

@end

@implementation MySenderBookingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    
    titleLabel.text = @"预约列表";
    
    bookingList = [[BookingListData alloc]init];
    tableMain.refreshDelegate = self;
    [tableMain becomeRefreshing:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return bookingList.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 110;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellTableIdentifier = @"MySenderBookingCellStr";
    
    MySenderBookingCell *cell = (MySenderBookingCell *)[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
    if (!cell)
    {
        cell = (MySenderBookingCell *)[[[NSBundle mainBundle] loadNibNamed:@"MySenderBookingCell" owner:self options:nil] objectAtIndex:0];
    }
    [cell fillDateWith:[bookingList.dataArray objectAtIndex:indexPath.row]];
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    BookingInfoData * info = [bookingList.dataArray objectAtIndex:indexPath.row];
    BookingDetailsViewController * detail = [[BookingDetailsViewController alloc]initWithNibName:@"BookingDetailsViewController" bundle:nil];
    detail.strPatientId = info.booking_patientId;
    detail.detailsStatusCode = info.booking_statusCode;
    detail.isMySender = YES;
    [self.navigationController pushViewController:detail animated:YES];
}


- (void)refreshTableViewDidTriggerRefresh:(RefreshTableView*)refreshTableView
{
    
    bookingList.urlPath = [NSString stringWithFormat:@"%@?username=%@&token=%@",[gProjConfig.dicAllUrl objectForKey:@"sendBookingUrl"],[gProjConfig.dicUserData objectForKey:USER_tel],[gProjConfig.dicUserData objectForKey:USER_token]];
    bookingList.strDataKey = @"data";
    
    [bookingList getLoadData:^(AFHTTPRequestOperation *operation, id responseObject)
    {
       // DLog(@"==%@",responseObject);
        
        if (bookingList.dataArray.count > 0)
        {
            viewNo_Data.hidden = YES;
            self.view.backgroundColor = UIColorFromRGB(0xf0,0xf0,0xf0);
            [tableMain reloadData];
            
        }else
        {
            viewNo_Data.hidden = NO;
            self.view.backgroundColor = [UIColor whiteColor];
        }
        
        tableMain.backgroundColor = self.view.backgroundColor;
        [refreshTableView refreshFinished];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [refreshTableView refreshFinished];
         HUDShowRequestError(error.domain, self.view)
    }];
    
}






- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end








